#include "scene.h"
#include <QtCore/QVectorIterator>
#include <QtCore/QMutableVectorIterator>

void Scene::Fire()
{
    Bullet b;
    double px, py, pz, dx, dy, dz;
    SubjectiveView(px, py, pz, dx, dy, dz);
    b.setPosition(dx, py, dz);
    dx -= px;
    dz -= pz;
    b.SetDirection(0.25f * dx, 0.25f * dz);
    m_bullets << b;
}

void Scene::AnimateBullets()
{
    QMutableVectorIterator<Bullet> it(m_bullets);

    while(it.hasNext())
    {
	    Bullet& b = it.next();
	    b.Advance();
	    int cell = b.cell(m_rows, m_columns);
	    if(cell >= 0)
	    {
		cell_state_t kind = m_tauler.at(cell);
		if(kind >= enemy0)
		{
		    it.remove();
		    m_tauler[cell] = empty;
		    m_NumBaddies--;
		}
		else if(kind == wall)
		{
		    it.remove();
		}
	    }
	    else it.remove();
    }
}
